#leetcode题目14：最长公共前缀
#难度：简单
#时间复杂度：O(n)
#空间复杂度：O(1)
#方法：模拟
#目前暂时还没有吃透
from typing import List

class Solution:
    def longestCommonPrefix(self, strs: List[str]) -> str:
        if not strs:
            return ""
        
        for i in range(len(strs[0])):
            for str in strs:
                if i>=len(str) or str[i]!=strs[0][i]:
                    return strs[0][:i]
        return strs[0]

#测试数据
strs=["flower","flow","flight"]
#预期输出：fl
solution=Solution()
print(solution.longestCommonPrefix(strs))

strs=["dog","racecar","car"]
#预期输出：""
solution=Solution()
print(solution.longestCommonPrefix(strs))